package com.project.class3_30;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadTest {
    public static void main(String[] args) {
        FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int sum = 0;
                for(int i=0;i<=100;i++){
                    sum += i;
                }

                return sum;
            }
        });
        //启动线程
        new Thread(task).start();
        try {
            //得到方法执行后的返回结果
            Integer x = task.get();
            System.out.println(x);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
